import apis from "../apis/index.js"
const login = (updata) => {
	if (updata) uni.removeStorageSync('token')
	uni.getStorage({
		key: "token",
		success: () => {
			bind()
		},
		fail: () => {
			uni.login({
				timeout: 4000,
				success: loginData => {
					apis['code2session']({
						code: loginData.code
					}).then(tokenData => {
						uni.setStorageSync('token', tokenData.obj.jwt.token)
						bind()
					})
				}
			})
		}
	})
}
const bind = () => {
	uni.getStorage({
		key: "bindId",
		success: (bindData) => {
			uni.removeStorageSync('bindId')
			apis['bind']({ scene: bindData.data }).then(res => {
				logs('用户已绑定')
			})
		}
	})
}
export default login
